package org.lennon.demo.ddd.ticket;

import org.lennon.demo.ddd.ticket.aggregate.command.TicketCreateCommand;
import org.lennon.demo.ddd.ticket.aggregate.command.TicketGiveOutCommand;
import org.lennon.demo.ddd.ticket.aggregate.command.TicketReduceCommand;
import org.lennon.demo.ddd.ticket.service.TicketAppicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/ddd")
@RestController
public class TicketController {

    @Autowired
    private TicketAppicationService ticketAppicationService;


    /**
     * 创建用户课时券
     */
    @PostMapping("/create")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void create(@RequestBody TicketCreateCommand ticketCreateCommand){
        ticketAppicationService.create(ticketCreateCommand);
    }

    /**
     * 赠送课时券
     */
    @PostMapping("/giveout")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void giveOut(@RequestBody TicketGiveOutCommand ticketGiveOutCommand) {
        ticketAppicationService.giveOut(ticketGiveOutCommand);
    }

    /**
     * 扣券
     */
    @PostMapping("/reduce")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void reduce(@RequestBody TicketReduceCommand ticketReduceCommand) {
        ticketAppicationService.reduce(ticketReduceCommand);
    }
}
